package com.zhao.servlet;

import java.io.IOException;
import java.security.DigestException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zhao.base.TokenThread;
import com.zhao.util.Sha1Util;
import com.zhao.util.SignUtil;

import net.sf.json.JSONObject;


/**
 * 获取权限验证参数
 * @author zhaowj
 * @date2018年1月25日 下午10:20:07
 */
@WebServlet("/wxConfigServlet")
public class WxConfigServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
 
    public WxConfigServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String jsapi_ticket=TokenThread.ticket.getTicket();
		String noncestr=SignUtil.getSJStr();
		String url=request.getHeader("referer");
		String timestamp=SignUtil.timeSequenceNo();
 		
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("jsapi_ticket",jsapi_ticket);
		map.put("noncestr",noncestr);
		map.put("timestamp",timestamp);
		map.put("url",url);
		
		String signature="";
		String str = "jsapi_ticket=" + jsapi_ticket + "&noncestr=" + noncestr + "&timestamp=" + timestamp + "&url=" + url;
		try {
			signature=Sha1Util.SHA1(str);
		} catch (Exception e) {
		}
		map.put("signature", signature);
		String json=JSONObject.fromObject(map).toString();
		response.getWriter().print(json);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
	
}
